# -*- coding: utf-8 -*-
"""
Created on Mon Oct 30 12:25:01 2017

@author: xuanlei
"""
import pandas as pd
import numpy as np
import sklearn.preprocessing as prep
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import DAencoder


def encoder_data(xr,df):#xr,做数据标准化训练str mean
    
    y = df.label
    dfx = df.drop(['label'],axis=1)
    tests_data = DAencoder.standard_scale(xr,dfx)
    tf.reset_default_graph()
    model = DAencoder.AdditiveGaussianNoiseAutoencoder(60,52,42,52,LR=0.001)#与训练时参数一致
    saver = tf.train.Saver()
    with tf.Session() as sess:
        init_op = tf.global_variables_initializer()
        sess.run(init_op)
        saver.restore(sess, 'adencoder/para_log')
        with tf.variable_scope('scope', reuse=True):
            feed_dict_test = {model.x:tests_data}
#            vail_predict = sess.run(model.pred, feed_dict=feed_dict_test)
            vail_predict = sess.run(model.h2_y,feed_dict=feed_dict_test)
        endata = pd.DataFrame(vail_predict)
        endata['label'] = list(y)
        return endata
        
      